using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using BusinessObject;
namespace Autenticazione
{
	public class Atleta : Page
	{
		protected HtmlForm form1;
		protected Label lblFullName;
		protected TextBox txtFullName;
		protected RequiredFieldValidator FullNameValidator;
		protected Label lblSesso;
		protected DropDownList cboSesso;
		protected Label lblBirthDay;
		protected DropDownList cboBirthMonth;
		protected DropDownList cboBirthYear;
		protected DropDownList cboBirthDay;
		protected Label lblBelt;
		protected DropDownList cboBelt;
		protected Label lblPeso;
		protected TextBox txtPeso;
		protected RequiredFieldValidator RegPeso;
		protected RegularExpressionValidator RegExprPeso;
		protected Label msgInfoAtleti;
		protected Label lblGrapplinLevel;
		protected DropDownList ddlGrapplingLevel;
		protected Label lblMatchFullContact;
		protected TextBox txtMatchFullContact;
		protected RequiredFieldValidator ReqValMatchFullContact;
		protected RegularExpressionValidator RegMatch;
		protected Label lblMatchLowKick;
		protected TextBox txtMatchLowKick;
		protected RequiredFieldValidator ReqMatchLowKick;
		protected RegularExpressionValidator RegMatchLowKick;
		protected Label lblK1Rules;
		protected TextBox txtMatchK1Rules;
		protected RequiredFieldValidator ReqK1Rules;
		protected RegularExpressionValidator RegtxtMatchK1Rules;
		protected Button btnSalvaAtleta;
		protected void Page_Load(object sender, EventArgs e)
		{
			Cintura belt = new Cintura();
			if (this.Session["EMail"] == null)
			{
				base.Response.Redirect("Autenticazione.aspx");
			}
			if (!base.IsPostBack)
			{
				Tools.FillComboMesi(this.cboBirthMonth);
				Tools.FillComboYears(this.cboBirthYear);
				Tools.FillComboDaysInMonthSelected(this.cboBirthDay, int.Parse(this.cboBirthMonth.SelectedValue), int.Parse(this.cboBirthYear.SelectedValue));
				Tools.FillComboGender(this.cboSesso);
				Tools.FillCombo(this.cboBelt, belt.GetTbBelts(), "Id", "Belt");
				Tools.FillGrapplingLevel(this.ddlGrapplingLevel);
			}
		}
		protected void btnSalvaAtleta_Click(object sender, EventArgs e)
		{
			BusinessObject.Atleta atleta = new BusinessObject.Atleta();
			if (this.Session["EMail"] == null)
			{
				base.Response.Redirect("Autenticazione.aspx");
			}
			atleta.EMail = this.Session["EMail"].ToString();
			atleta.FullName = this.txtFullName.Text.Replace("'", "''");
			atleta.Gender = int.Parse(this.cboSesso.SelectedValue);
			atleta.BirthDayString = string.Format("{0}/{1}/{2}", this.cboBirthYear.SelectedValue, this.cboBirthMonth.SelectedValue, this.cboBirthDay.SelectedValue);
			atleta.Belt = int.Parse(this.cboBelt.SelectedValue);
			atleta.Weight = float.Parse(this.txtPeso.Text);
			atleta.GrapplingLevel = this.ddlGrapplingLevel.SelectedValue;
			atleta.MatchFullContact = int.Parse(this.txtMatchFullContact.Text);
			atleta.MatchLowKick = int.Parse(this.txtMatchLowKick.Text);
			atleta.MatchK1Rules = int.Parse(this.txtMatchK1Rules.Text);
			if (this.Page.IsValid)
			{
				atleta.Salva();
				base.ClientScript.RegisterClientScriptBlock(base.GetType(), "Close", "window.close(); window.opener.Aggiorna()", true);
			}
		}
		protected void Year_Changed(object sender, EventArgs e)
		{
			Tools.FillComboDaysInMonthSelected(this.cboBirthDay, int.Parse(this.cboBirthMonth.SelectedValue), int.Parse(this.cboBirthYear.SelectedValue));
		}
		protected void Month_Changed(object sender, EventArgs e)
		{
			Tools.FillComboDaysInMonthSelected(this.cboBirthDay, int.Parse(this.cboBirthMonth.SelectedValue), int.Parse(this.cboBirthYear.SelectedValue));
		}
	}
}
